#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QTimer>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    //创建定时器
    //startTimer(1000);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::timerEvent(QTimerEvent *event)
{
    static int num = 1;
    this->ui->lcdNumber->display(num++);
}

void Widget::on_pushButton_start_clicked()
{
    //创建定时器 设置1秒一次
    this->mTimeId = startTimer(1000);
}

void Widget::on_pushButton_stop_clicked()
{
    //停止定时器
    killTimer(mTimeId);
}

void Widget::on_pushButton_start_3_clicked()
{
    mTimer = new QTimer(this);
    connect(mTimer,&QTimer::timeout,[=](){
        static int num = 1;
        this->ui->lcdNumber_3->display(num++);
    });
    mTimer->start(10);
}

void Widget::on_pushButton_stop_3_clicked()
{
    mTimer->stop();

}
